# coding=utf-8
import thread
import urllib2
import sys

reload(sys)
sys.setdefaultencoding('utf-8')
from client import Client
from server.base.beanret import BeanRet
from config import Config

'''
该类是pony编写的类:在该类中的execute()方法中，本来调用getCmd()获取到一个cmd指令，然后去执行。
现改为：不在调用getCmd()方法获取指令，而是添加一个形参接收cmd指令，然后去执行。
'''


class Execute:

    def execute(self, cmd):
        '''
        接收cmd指令并执行
        :return:
        '''
        print "终端" + str(Client().clientId) + "执行了指令" + str(cmd)
        client = Client()
        if cmd is None:
            return False
        # 截取字符串
        arrays = str(cmd).split(",")
        cmd = arrays[0]
        # 解析：无人机指令1，发货终端和接收终端的经纬度和角度
        send_lon = None
        send_lat = None
        send_angle = None
        accept_lon = None
        accept_lon = None
        accept_angle = None
        if arrays.__len__() > 1:
            send_lon = arrays[1]
            send_lat = arrays[2]
            send_angle = arrays[3]
            accept_lon = arrays[4]
            accept_lat = arrays[5]
            accept_angle = arrays[6]

        if cmd == "终端指令1A":  # 终端指令1A
            thread.start_new_thread(client.notify, (cmd,))
            pass
        elif cmd == "终端指令1B":  # 终端指令1B
            thread.start_new_thread(client.notify, (cmd,))
            pass
        elif cmd == "终端指令2A":  # 终端指令2A
            thread.start_new_thread(client.notify, (cmd,))
            pass
        elif cmd == "终端指令2B":  # 终端指令2B
            thread.start_new_thread(client.notify, (cmd,))
            pass
        elif cmd == "终端指令2B":  # 终端指令2B
            thread.start_new_thread(client.notify, (cmd,))
            pass
        elif cmd == "终端指令3A":  # 终端指令3A
            thread.start_new_thread(client.notify, (cmd,))
            pass
        elif cmd == "终端指令3B":  # 终端指令3B
            thread.start_new_thread(client.notify, (cmd,))
            pass
        elif cmd == "终端指令4A":  # 终端指令4A
            thread.start_new_thread(client.notify, (cmd,))
            pass
        elif cmd == "终端指令4B":  # 终端指令4B
            thread.start_new_thread(client.notify, (cmd,))
            pass
        elif cmd == "无人机指令1":  # 无人机指令1
            thread.start_new_thread(client.notify, (cmd,))
            pass
        elif cmd == "无人机指令2":  # 无人机指令2
            thread.start_new_thread(client.notify, (cmd,))
            pass
        elif cmd == "无人机指令3":  # 无人机指令3
            thread.start_new_thread(client.notify, (cmd,))
            pass
        elif cmd == "无人机指令4":  # 无人机指令4
            thread.start_new_thread(client.notify, (cmd,))
            pass
        elif cmd == "无人机指令5":  # 无人机指令5
            thread.start_new_thread(client.notify, (cmd,))
            pass
        return True


